

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" type="image/png" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="CodeHope">
  <meta name="author" content="CodeHope">
  <meta name="keywords" content="希望">
  <title>Css-Flex布局完全总结 - CodeHope</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      
        
          
          
          
        
        <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.22.0/themes/prism-tomorrow.min.css" />
      
      
        <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.22.0/plugins/line-numbers/prism-line-numbers.min.css" />
      
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css" />
  



<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"quancundexiwang.wang","root":"/","version":"1.8.7","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":true,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"onlypost":true},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":"Mi65hxq7VAFUDwOLeIGAOgiV-gzGzoHsz","app_key":"hMuhiD4FRqhns4giqLiEH9HG","server_url":null}}};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.3.0"></head>


<body>
  <header style="height: 80vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>CodeHope</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                村头
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                我
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=444247071,3464022379&fm=26&gp=0.jpg') repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="Css-Flex布局完全总结">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2020-09-12 02:44" pubdate>
        2020年9月12日 凌晨
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      1.5k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      20
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
            <div class="scroll-down-bar">
              <i class="iconfont icon-arrowdown"></i>
            </div>
          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Css-Flex布局完全总结</h1>
            
            <div class="markdown-body">
              <h2 id="1-Css-flex布局"><a href="#1-Css-flex布局" class="headerlink" title="1.Css-flex布局"></a>1.Css-flex布局</h2><blockquote>
<p> <code>Flex</code> 是 <code>Flexible Box</code> 的缩写，意为”弹性布局”</p>
</blockquote>
<blockquote>
<p><code>任何一个容器</code>都可以指定为 Flex 布局。</p>
</blockquote>
<div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.box</span><span class="token punctuation">&#123;</span>
  <span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></div>
<blockquote>
<p><code>行内元素</code>也可以使用 Flex 布局。</p>
</blockquote>
<div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.box</span><span class="token punctuation">&#123;</span>
  <span class="token property">display</span><span class="token punctuation">:</span> inline-flex<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></div>
<blockquote>
<p>Webkit 内核的浏览器，必须加上-webkit前缀。</p>
</blockquote>
<div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.box</span><span class="token punctuation">&#123;</span>
  <span class="token property">display</span><span class="token punctuation">:</span> -webkit-flex<span class="token punctuation">;</span> <span class="token comment">/* Safari */</span>
  <span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre></div>
<blockquote>
<p>注意，设为 Flex 布局以后，子元素的float、clear和vertical-align属性将失效。</p>
</blockquote>
<h2 id="2-基本概念"><a href="#2-基本概念" class="headerlink" title="2.基本概念"></a>2.基本概念</h2><blockquote>
<p>Flex 布局的元素，称为 Flex 容器（flex container） ,简称”容器”</p>
</blockquote>
<blockquote>
<p>它的所有子元素自动成为容器成员，称为 Flex 项目（flex item），简称”项目”。</p>
</blockquote>
<h2 id="3-容器的属性"><a href="#3-容器的属性" class="headerlink" title="3.容器的属性"></a>3.容器的属性</h2><ul>
<li><h3 id="flex-direction"><a href="#flex-direction" class="headerlink" title="flex-direction"></a><font style="color:red;font-weight:bolder;font-size:1.5rem">flex-direction</font></h3><blockquote>
<p>flex-direction属性决定主轴的方向（即项目的排列方向）。</p>
</blockquote>
  <div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.box</span> <span class="token punctuation">&#123;</span>
  <span class="token property">flex-direction</span><span class="token punctuation">:</span> row | row-reverse | column | column-reverse<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></div>
<p>  它可能有4个值。</p>
<ul>
<li><code>row(默认)</code>:——————主轴为水平方向，起点在左端。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912030504.png" srcset="/img/loading.gif"></li>
<li><code>row-reverse</code>:——————主轴为水平方向，起点在右端。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912030542.png" srcset="/img/loading.gif"></li>
<li><code>column</code>:——————主轴为垂直方向，起点在上沿。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912030610.png" srcset="/img/loading.gif"></li>
<li><code>column-reverse</code>——————主轴为垂直方向，起点在下沿。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912030641.png" srcset="/img/loading.gif"></li>
</ul>
</li>
<li><h3 id="flex-wrap"><a href="#flex-wrap" class="headerlink" title="flex-wrap"></a><font style="color:red;font-weight:bolder;font-size:1.5rem">flex-wrap</font></h3><blockquote>
<p>默认情况下，项目都排在一条线（又称”轴线”）上。flex-wrap属性定义，如果一条轴线排不下，如何换行。</p>
</blockquote>
  <div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.box</span><span class="token punctuation">&#123;</span>
 <span class="token property">flex-wrap</span><span class="token punctuation">:</span> nowrap | wrap | wrap-reverse<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></div>
<ul>
<li><p>它可能取三个值。</p>
</li>
<li><p><code>nowrap</code>（默认）—————— 不换行。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912030504.png" srcset="/img/loading.gif"></p>
</li>
<li><p><code>wrap</code>—————— 换行，第一行在上方。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912030821.png" srcset="/img/loading.gif"></p>
</li>
<li><p><code>wrap-reverse</code>—————— 换行，第一行在下方。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912030855.png" srcset="/img/loading.gif"></p>
</li>
</ul>
</li>
<li><h3 id="flex-flow"><a href="#flex-flow" class="headerlink" title="flex-flow"></a><font style="color:red;font-weight:bolder;font-size:1.5rem">flex-flow</font></h3><blockquote>
<p>flex-flow属性是<code>flex-direction</code>属性和<code>flex-wrap</code>属性的简写形式，默认值为<code>row nowrap</code>。</p>
</blockquote>
  <div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.box</span> <span class="token punctuation">&#123;</span>
    <span class="token property">flex-flow</span><span class="token punctuation">:</span> &lt;flex-direction> || &lt;flex-wrap><span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></div></li>
<li><h3 id="justify-content"><a href="#justify-content" class="headerlink" title="justify-content"></a><font style="color:red;font-weight:bolder;font-size:1.5rem">justify-content</font></h3><blockquote>
<p>justify-content属性定义了项目在主轴上的对齐方式。</p>
</blockquote>
  <div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.box</span> <span class="token punctuation">&#123;</span>
    <span class="token property">justify-content</span><span class="token punctuation">:</span> flex-start | flex-end | center | space-between | space-around<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></div>
<ul>
<li><code>flex-start</code> ——（默认值）：左对齐<br><img src="http://qiniuyun.quancundexiwang.wang/20200912031632.png" srcset="/img/loading.gif"></li>
<li><code>flex-end</code>—————右对齐<br><img src="http://qiniuyun.quancundexiwang.wang/20200912031711.png" srcset="/img/loading.gif"></li>
<li><code>center</code>—————— 居中<br><img src="http://qiniuyun.quancundexiwang.wang/20200912031746.png" srcset="/img/loading.gif"></li>
<li><code>space-between</code> —— 两端对齐，项目之间的间隔都相等。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912031824.png" srcset="/img/loading.gif"></li>
<li><code>space-around</code> ——— 每个项目两侧的间隔相等。所以，项目之间的间隔比项目与边框的间隔大一倍。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912031908.png" srcset="/img/loading.gif"></li>
</ul>
</li>
<li><h3 id="align-items"><a href="#align-items" class="headerlink" title="align-items"></a><font style="color:red;font-weight:bolder;font-size:1.5rem">align-items</font></h3><blockquote>
<p>align-items属性定义项目在交叉轴(副轴)上如何对齐。</p>
</blockquote>
<div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.box</span> <span class="token punctuation">&#123;</span>
  <span class="token property">align-items</span><span class="token punctuation">:</span> flex-start | flex-end | center | baseline | stretch<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></div>
<ul>
<li><code>flex-start</code> ——— 交叉轴的起点对齐。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912094308.png" srcset="/img/loading.gif"></li>
<li><code>flex-end</code>———交叉轴的终点对齐。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912094403.png" srcset="/img/loading.gif"></li>
<li><code>center</code>———交叉轴的中点对齐。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912094453.png" srcset="/img/loading.gif"></li>
<li><code>baseline</code>———项目的第一行文字的基线对齐。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912094649.png" srcset="/img/loading.gif"></li>
<li><code>stretch</code>（默认值）——— 如果项目未设置高度或设为auto，将占满整个容器的高度。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912093915.png" srcset="/img/loading.gif"></li>
</ul>
</li>
<li><h3 id="align-content"><a href="#align-content" class="headerlink" title="align-content"></a><font style="color:red;font-weight:bolder;font-size:1.5rem">align-content</font></h3><blockquote>
<p>align-content属性定义了多根轴线的对齐方式。</p>
</blockquote>
</li>
</ul>
<div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.box</span> <span class="token punctuation">&#123;</span>
  <span class="token property">align-content</span><span class="token punctuation">:</span> flex-start | flex-end | center | space-between | space-around | stretch<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></div>
<blockquote>
<p>如果项目只有一根轴线，该属性不起作用。所以我们要定义一个超出flex-wrap为wrap的情况。（记的不要定义项目的高度如果做demo的话可能会影响实际效果）</p>
</blockquote>
<div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.flex-wrap</span><span class="token punctuation">&#123;</span>
    <span class="token property">width</span><span class="token punctuation">:</span> 300px<span class="token punctuation">;</span>
    <span class="token property">height</span><span class="token punctuation">:</span> 200px<span class="token punctuation">;</span>
    <span class="token property">display</span><span class="token punctuation">:</span> flex<span class="token punctuation">;</span>
    <span class="token property">border</span><span class="token punctuation">:</span>  1px solid red<span class="token punctuation">;</span>
    <span class="token property">flex-wrap</span><span class="token punctuation">:</span> wrap<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span>
<span class="token selector">.flex-item</span><span class="token punctuation">&#123;</span>
    <span class="token property">background-color</span><span class="token punctuation">:</span> aqua<span class="token punctuation">;</span>
    <span class="token property">width</span><span class="token punctuation">:</span> 30px<span class="token punctuation">;</span>
    <span class="token property">text-align</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>
    <span class="token property">line-height</span><span class="token punctuation">:</span> 30px<span class="token punctuation">;</span>
    <span class="token property">margin</span><span class="token punctuation">:</span> 2px<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div>
<ul>
<li><p><code>stretch</code>（默认值）：轴线占满整个交叉轴。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912100306.png" srcset="/img/loading.gif"></p>
</li>
<li><p><code> flex-start</code>：与交叉轴的起点对齐。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912100656.png" srcset="/img/loading.gif"></p>
</li>
<li><p><code>flex-end</code>：与交叉轴的终点对齐。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912100738.png" srcset="/img/loading.gif"></p>
</li>
<li><p><code>center</code>：与交叉轴的中点对齐。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912100827.png" srcset="/img/loading.gif"></p>
</li>
<li><p><code>space-between</code>：与交叉轴两端对齐，轴线之间的间隔平均分布。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912100902.png" srcset="/img/loading.gif"></p>
</li>
<li><p><code>space-around</code>：每根轴线两侧的间隔都相等。所以，轴线之间的间隔比轴线与边框的间隔+ 大一倍。<br><img src="http://qiniuyun.quancundexiwang.wang/20200912101002.png" srcset="/img/loading.gif"></p>
<h2 id="4-项目的属性"><a href="#4-项目的属性" class="headerlink" title="4.项目的属性"></a>4.项目的属性</h2></li>
</ul>
<ul>
<li><h3 id="order"><a href="#order" class="headerlink" title="order"></a><font style="color:red;font-weight:bolder;font-size:1.5rem">order</font></h3><blockquote>
<p>order属性定义项目沿着主轴方向的排列顺序。数值越小，排列越靠前，默认为0。</p>
</blockquote>
  <div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.flex-item:nth-child(1)</span><span class="token punctuation">&#123;</span>
  <span class="token property">width</span><span class="token punctuation">:</span> 50px<span class="token punctuation">;</span>
  <span class="token property">order</span><span class="token punctuation">:</span>1
<span class="token punctuation">&#125;</span>
<span class="token selector">.flex-item:nth-child(2)</span><span class="token punctuation">&#123;</span>
  <span class="token property">width</span><span class="token punctuation">:</span> 30px<span class="token punctuation">;</span>
  <span class="token property">order</span><span class="token punctuation">:</span> -1<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span> 
<span class="token selector">.flex-item:nth-child(3)</span><span class="token punctuation">&#123;</span>
  <span class="token property">width</span><span class="token punctuation">:</span> 50px<span class="token punctuation">;</span>
  <span class="token property">order</span><span class="token punctuation">:</span> -2<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span>
<span class="token selector">.flex-item:nth-child(4)</span><span class="token punctuation">&#123;</span>
  <span class="token property">width</span><span class="token punctuation">:</span> 70px<span class="token punctuation">;</span>
  <span class="token property">order</span><span class="token punctuation">:</span>4<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span>
<span class="token selector">.flex-item:nth-child(5)</span><span class="token punctuation">&#123;</span>
  <span class="token property">width</span><span class="token punctuation">:</span> 30px<span class="token punctuation">;</span>
  <span class="token property">order</span><span class="token punctuation">:</span>3<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div>
<p>  <img src="http://qiniuyun.quancundexiwang.wang/20200912101724.png" srcset="/img/loading.gif"></p>
</li>
<li><h3 id="flex-grow"><a href="#flex-grow" class="headerlink" title="flex-grow"></a><font style="color:red;font-weight:bolder;font-size:1.5rem">flex-grow</font></h3><blockquote>
<p>flex-grow属性定义项目的放大比例，</p>
</blockquote>
<div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.item</span> <span class="token punctuation">&#123;</span>
  <span class="token property">flex-grow</span><span class="token punctuation">:</span> &lt;number><span class="token punctuation">;</span> <span class="token comment">/* default 0 */</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></div>
<p><font style="font-size:1.2rem"><code>1.默认为0，即如果存在剩余空间，也不放大</code> </font><br><img src="http://qiniuyun.quancundexiwang.wang/20200912105335.png" srcset="/img/loading.gif"></p>
<p><font style="font-size:1.2rem"><code>2.如果所有项目的flex-grow属性都为1，则它们将等分剩余空间（如果有的话）</code></font></p>
<div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token property">flex-grow</span><span class="token punctuation">:</span> 1<span class="token punctuation">;</span><span aria-hidden="true" class="line-numbers-rows"><span></span></span></code></pre></div>
<p><img src="http://qiniuyun.quancundexiwang.wang/20200912105435.png" srcset="/img/loading.gif"></p>
</li>
</ul>
<p><font style="font-size:1.2rem"><code>3.如果一个项目的flex-grow属性为n，其他项目都为1，则前者占据的剩余空间将比其他项多n倍。（如果空间不够，不一定真的能比其他项大n倍）</code></font><br>  <div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.flex-item:nth-child(1)</span><span class="token punctuation">&#123;</span>
    <span class="token property">flex-grow</span><span class="token punctuation">:</span> 1<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span>
<span class="token selector">.flex-item:nth-child(2)</span><span class="token punctuation">&#123;</span>
    <span class="token property">flex-grow</span><span class="token punctuation">:</span> 2<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span>
<span class="token selector">.flex-item:nth-child(3)</span><span class="token punctuation">&#123;</span>
    <span class="token property">flex-grow</span><span class="token punctuation">:</span> 1<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div><br>  <img src="http://qiniuyun.quancundexiwang.wang/20200912105640.png" srcset="/img/loading.gif"></p>
<ul>
<li><h3 id="flex-shrink"><a href="#flex-shrink" class="headerlink" title="flex-shrink"></a><font style="color:red;font-weight:bolder;font-size:1.5rem">flex-shrink</font></h3><blockquote>
<p>flex-shrink属性定义了项目的缩小比例，负值对该属性无效。</p>
</blockquote>
  <div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.item</span> <span class="token punctuation">&#123;</span>
  <span class="token property">flex-shrink</span><span class="token punctuation">:</span> &lt;number><span class="token punctuation">;</span> <span class="token comment">/* default 1 */</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></div>
<p><font style="font-size:1.2rem"><code>1.默认为1，即如果空间不足，该项目将缩小。 </code></font></p>
<div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.item</span> <span class="token punctuation">&#123;</span>
  <span class="token property">flex-shrink</span><span class="token punctuation">:</span> 1<span class="token punctuation">;</span>
  <span class="token property">width</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span></span></code></pre></div>
<p><img src="http://qiniuyun.quancundexiwang.wang/20200912110609.png" srcset="/img/loading.gif"></p>
<p> <font style="font-size:1.2rem"><code>2.如果一个项目的flex-shrink属性为0，其他项目都为1，则空间不足时，前者不缩小。</code></font></p>
 <div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.flex-item</span><span class="token punctuation">&#123;</span>
  <span class="token property">width</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span>
<span class="token selector">.flex-item:nth-child(1)</span><span class="token punctuation">&#123;</span>
  <span class="token property">flex-shrink</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span>
<span class="token selector">.flex-item:nth-child(3)</span><span class="token punctuation">&#123;</span>
  <span class="token property">flex-shrink</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div>
<p><img src="http://qiniuyun.quancundexiwang.wang/20200912111043.png" srcset="/img/loading.gif"></p>
</li>
<li><h3 id="flex-basis"><a href="#flex-basis" class="headerlink" title="flex-basis"></a><font style="color:red;font-weight:bolder;font-size:1.5rem">flex-basis</font></h3><blockquote>
<p>flex-basis属性定义了在分配多余空间之前，项目占据的主轴空间（main size）。浏览器根据这个属性，计算主轴是否有多余空间。</p>
</blockquote>
<div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.item</span> <span class="token punctuation">&#123;</span>
  <span class="token property">flex-basis</span><span class="token punctuation">:</span> &lt;length> | auto<span class="token punctuation">;</span> <span class="token comment">/* default auto */</span>
<span class="token punctuation">&#125;</span> <span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></div>
<p> <font style="font-size:1.2rem"><code>1.它的默认值为auto，即项目的本来大小</code></font></p>
 <div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"> <span class="token selector">.flex-item</span><span class="token punctuation">&#123;</span>
    <span class="token property">width</span><span class="token punctuation">:</span> 30px<span class="token punctuation">;</span>
    <span class="token property">flex-grow</span><span class="token punctuation">:</span> 0<span class="token punctuation">;</span> //默认为0不放大
    <span class="token property">flex-basis</span><span class="token punctuation">:</span>auto<span class="token punctuation">;</span>//默认为项目本身大小
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span></span></code></pre></div>
<p><img src="http://qiniuyun.quancundexiwang.wang/20200912112053.png" srcset="/img/loading.gif"><br><font style="font-size:1.2rem"><code>2.它可以设为跟width或height属性一样的值（比如350px），则项目将占据固定空间。</code></font></p>
<div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.flex-item:nth-child(1)</span><span class="token punctuation">&#123;</span>
<span class="token punctuation">&#125;</span>
<span class="token selector">.flex-item:nth-child(2)</span><span class="token punctuation">&#123;</span>
  <span class="token property">flex-basis</span><span class="token punctuation">:</span> 120px<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span>
<span class="token selector">.flex-item:nth-child(3)</span><span class="token punctuation">&#123;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div>
<p><img src="http://qiniuyun.quancundexiwang.wang/20200912112411.png" srcset="/img/loading.gif"></p>
</li>
<li><h3 id="flex"><a href="#flex" class="headerlink" title="flex"></a><font style="color:red;font-weight:bolder;font-size:1.5rem">flex</font></h3></li>
</ul>
<blockquote>
<p>flex属性是<code>flex-grow</code>, <code>flex-shrink</code> 和<code>flex-basis</code>的简写，默认值为<code>0 1 auto</code>。后两个属性可选。</p>
</blockquote>
  <div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.item</span> <span class="token punctuation">&#123;</span>
  <span class="token property">flex</span><span class="token punctuation">:</span> none | [ &lt;<span class="token string">'flex-grow'</span>> &lt;<span class="token string">'flex-shrink'</span>>? || &lt;<span class="token string">'flex-basis'</span>> ]
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></div>
<p>  该属性有两个快捷值：<code>auto (1 1 auto)</code> 和 <code>none (0 0 auto)。</code></p>
<p>  建议优先使用这个属性，而不是单独写三个分离的属性，因为浏览器会推算相关值。</p>
<ul>
<li><h3 id="align-self"><a href="#align-self" class="headerlink" title="align-self"></a><font style="color:red;font-weight:bolder;font-size:1.5rem">align-self</font></h3>  <div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.item</span> <span class="token punctuation">&#123;</span>
  <span class="token property">align-self</span><span class="token punctuation">:</span> auto | flex-start | flex-end | center | baseline | stretch<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span></span></code></pre></div>
<blockquote>
<p><code>align-self</code>属性<code>允许单个项目有与其他项目不一样的对齐方式</code>，可覆盖<code>align-items</code>属性。默认值为<code>auto，表示继承父元素的align-items属性</code>，如果没有父元素，则<code>等同于stretch。</code></p>
</blockquote>
<div class="code-wrapper"><pre class="line-numbers language-css" data-language="css"><code class="language-css"><span class="token selector">.flex-wrap</span><span class="token punctuation">&#123;</span>
    <span class="token property">align-items</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span>
<span class="token selector">.flex-item:nth-child(1)</span><span class="token punctuation">&#123;</span>
    <span class="token property">align-self</span><span class="token punctuation">:</span> flex-start<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span>
<span class="token selector">.flex-item:nth-child(2)</span><span class="token punctuation">&#123;</span>
    <span class="token property">align-self</span><span class="token punctuation">:</span> flex-end<span class="token punctuation">;</span>
<span class="token punctuation">&#125;</span><span aria-hidden="true" class="line-numbers-rows"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></code></pre></div>
<p><img src="http://qiniuyun.quancundexiwang.wang/20200912113547.png" srcset="/img/loading.gif"></p>
</li>
</ul>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/%E5%89%8D%E7%AB%AF/">前端</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Css%E5%B8%83%E5%B1%80/">Css布局</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！</p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/posts/22948/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Taro使用 Mobx 状态管理库</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/posts/50009/">
                        <span class="hidden-mobile">Koa项目的一些项目搭建习惯总结</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
              <!-- Comments -->
              <article class="comments" id="comments">
                
                
  <div id="vcomments"></div>
  <script type="text/javascript">
    Fluid.utils.waitElementVisible('vcomments', function() {
      Fluid.utils.createScript('https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js', function () {
        new Valine({
          el: "#vcomments",
          app_id: "Mi65hxq7VAFUDwOLeIGAOgiV-gzGzoHsz",
          app_key: "hMuhiD4FRqhns4giqLiEH9HG",
          placeholder: "说点什么",
          path: window.location.pathname,
          avatar: "retro",
          meta: ["nick","mail","link"],
          pageSize: "10",
          lang: "zh-CN",
          highlight: false,
          recordIP: false,
          serverURLs: "",
        });
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the
    <a target="_blank" href="https://valine.js.org" rel="nofollow noopener noopener">comments powered by Valine.</a>
  </noscript>


              </article>
            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
    

  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


  
  <!-- 备案信息 -->
  <div class="beian">
    <span>
      <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
        豫ICP备20009912号-1
      </a>
    </span>
    
  </div>


  
</footer>

<!-- SCRIPTS -->

  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":true,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  
    
      <script  src="/js/lazyload.js" ></script>
    
  



  
    
  



  <script  src="https://cdn.jsdelivr.net/npm/tocbot@4.12.0/dist/tocbot.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4.3.0/anchor.min.js" ></script>



  <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>




  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2.0.11/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
      typing(title)
      
    })(window, document);
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    (function () {
      var path = "http://qiniuyun.quancundexiwang.wang/xmlSearch.xml";
      var inputArea = document.querySelector("#local-search-input");
      inputArea.onclick = function () {
        searchFunc(path, 'local-search-input', 'local-search-result');
        this.onclick = null
      }
    })()
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>



</body>
</html>
